package testcase;

import org.junit.Test;

import junit.framework.TestCase;
import control.ItemController;
import entity.Pecies;
import entity.Card.Item;

public class ItemControllerTest extends TestCase{
	public class ItemControllerStub extends ItemController{
	}
	ItemControllerStub stub=new ItemControllerStub();
	
	public class PeciesStub extends Pecies{

		public PeciesStub(String imgs, String iconURL, String name, int self,
				int cropW, int cropH) {
			super(imgs, iconURL, name, self, cropW, cropH);
		}
		
	}
	PeciesStub pstub1=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub2=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub3=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub4=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub5=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub6=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub7=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	PeciesStub pstub8=new PeciesStub("/images/pieces/father.PNG","/images/pieces/icon/father_big.PNG", "N",10,80, 80);
	
	
	public class ItemStub extends Item{

		public ItemStub(Integer ID, String content, String title, String img,
				boolean isChinese) {
			super(ID, content, title, img, isChinese);
		}
	}
	ItemStub istub1=new ItemStub(0,"n","n","/images/pieces/father.PNG",true);
	ItemStub istub2=new ItemStub(1,"n","n","/images/pieces/father.PNG",true);
	ItemStub istub3=new ItemStub(2,"n","n","/images/pieces/father.PNG",true);
	ItemStub istub4=new ItemStub(3,"n","n","/images/pieces/father.PNG",true);
	
	@Test
	public void testdisplayitemcard(){
		 Item totest;
		
		 pstub1.setItem(istub1);
		 pstub1.setItem(istub2);
		 
		 totest=stub.displayItemCard(pstub1);
		 assertNull(totest);
		 
		 totest=stub.displayItemCard(pstub2);
		 assertNotNull(totest);
	}
	
	@Test
	public void testUpdateRoundUse(){
		istub1.setOwner(pstub2);
		istub1.setRoundUse(0);
		pstub2.setItem(istub1);
		pstub2.setItemUsing(istub1);
		stub.UpdateRoundUse(pstub2);
		assertEquals(pstub2.isItemUsing(),false);
		
		istub2.setOwner(pstub3);
		istub2.setRoundUse(2);
		pstub3.setItem(istub2);
		pstub3.setItemUsing(istub2);
		stub.UpdateRoundUse(pstub3);
		assertEquals(1,istub2.getRoundUse());
		
		stub.UpdateRoundUse(pstub4);
		assertEquals(pstub4.isItemUsing(),false);
	}

	@Test
	public void testuseItemEffect(){
		istub1.setOwner(pstub2);
		pstub2.setItem(istub1);
		pstub2.setItemUsing(istub1);
		int test0=stub.useItemEffect(1, pstub2);
		assertEquals(1,test0);
		
		istub2.setOwner(pstub3);
		pstub3.setItem(istub2);
		pstub3.setItemUsing(istub2);
		int test1=stub.useItemEffect(1, pstub3);
		assertEquals(1,test1);
		test1=stub.useItemEffect(-1, pstub3);
		assertEquals(0,test1);
		
		istub3.setOwner(pstub4);
		pstub4.setItem(istub3);
		pstub4.setItemUsing(istub3);
		int  test2=stub.useItemEffect(1, pstub4);
		assertEquals(1,test2);
		test2=stub.useItemEffect(-1, pstub4);
		assertEquals(0,test2);
		
		istub4.setOwner(pstub5);
		pstub5.setItem(istub4);
		pstub5.setItemUsing(istub4);
		int test3=stub.useItemEffect(2, pstub5);
		assertEquals(4,test3);
	}
	
}
